package com.party.notify.notifyPush.event;

import com.party.core.exception.BusinessException;
import com.party.core.model.notify.TargetTemplateType;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 众筹事项消息推送
 * Created by wei.li
 *
 * @date 2017/11/1 0001
 * @time 10:11
 */

@Service
public class EventSendFactory {

    @Resource(name = "eventAllCrowdfundService")
    private INotifyEventSendService eventAllCrowdfundService;

    @Resource(name = "eventSuccessCrowdfundService")
    private INotifyEventSendService eventSuccessCrowdfundService;

    @Resource(name = "eventUnderwayCordfundService")
    private INotifyEventSendService eventUnderwayCordfundService;

    /**
     * 获取发送器
     * @param targetTemplateType 模板类型
     * @return 发送器
     */
    public INotifyEventSendService getSender(TargetTemplateType targetTemplateType){
        if (targetTemplateType.getType().equals(1)){
            throw new BusinessException("不能发送活动推送");
        }

        if (TargetTemplateType.CROWDFUNF_ALL.getCode().equals(targetTemplateType.getCode())){
            return eventAllCrowdfundService;
        }
        else if (TargetTemplateType.CROWDFUND_SUCCESS.getCode().equals(targetTemplateType.getCode())){
            return eventSuccessCrowdfundService;
        }
        else if (TargetTemplateType.CROWDFUND_UNDERWAY.getCode().equals(targetTemplateType.getCode())){
            return eventUnderwayCordfundService;
        }
        return null;
    }
}
